<template>
	<view class="order">
		<!-- <view v-if="hasLogin"> -->
		<!-- 导航 -->
		<u-navbar back-text="申请平台介入" :back-text-style="textStyle" back-icon-color="#000000" style="font-weight: bold;font-family: PingFang SC;"></u-navbar>
		<!-- <u-navbar back-icon-color="#000000" title="申请平台介入" title-color="#3F3F3F" :title-bold="true" :background="background"></u-navbar> -->
		<!-- end -->
		<view>
			<view class="yes">
				<view>我们将会通过预留手机号联系您</view>
				<view>平台收到介入申请后将会沟通双方具体情况</view>
				<view>根据双方提供的材料决定本次售后申请的最后处理结果</view>
			</view>
			<view class="line"></view>
			<view class="want">
				<view class="wait1">您可以在本页面补充您的描述，尽可能详细</view>
			</view>
			<view class="source">
				<view class="texs" style="">
					<textarea id="border" value="" placeholder="请输入您的描述" v-model="comments" />
					<view class="choose">
						<view class="item" v-for="(item,index) in imgList" :key='index'>
							<image :src="item" mode="" ></image>
							<image class="no" src="../../static/icon/no.png" mode="" @click="del(index)"></image>
						</view>
						<view class="xiuxiu">
						<view class="item" v-if="imgList.length < 6">
							<image src="../../static/icon/cau.png" mode="" @click="unphoto()"></image>
						</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view style="height: 140rpx;"></view>
		<view class="footer">
			<view class="foot_mon">
					<u-button type="warning" shape="circle" @click="editMarket()">提交</u-button>
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				background:{
					backgroundColor: '#fca800',
				},
				timestamp: 86400,
				imgList:[],
				image_array:[],
				orderIssueId:''
			};
		},
		onLoad(option) {
			this.orderIssueId = option.orderIssueId
		},
		methods: {
			unphoto(){
				var _this = this
				if (this.imgList.length < 6) {
					var _this = this;
					uni.chooseImage({
						count: 6,
						success: function(res) {
							var arr = [];
							for (var i in res.tempFilePaths) {
								_this.imgList.push(res.tempFilePaths[i]);
							}
							if (res.tempFilePaths.length > 6) {
								uni.showToast({
									icon: 'none',
									title: '最多上传6张图片',
									duration: 1000
								});
							}
						}
					});
				} else {
					uni.showToast({
						icon: 'none',
						title: '最多上传6张图片',
						duration: 1000
					});
				}
			},
			editMarket(){
				var _this = this
				if(_this.imgList.length > 0){
					_this.image_array = []
					for (let k = 0; k < _this.imgList.length; k++) {
							uni.uploadFile({
								url: this.http.baseUrl +'/common/upload/batch',
								filePath: _this.imgList[k],
								name: 'file',
								fileType: 'image',
								success: (res) => {
									let url_href = JSON.parse(res.data).data[0];
									_this.image_array.push(url_href);
									if (_this.image_array.length == _this.imgList.length) {
										uni.hideLoading({
											title: '上传成功'
										})
										 _this.promotion()
									}
									
								}
							});
					}
				}else{
					 _this.promotion()
				}
			},
			promotion(){
				var _this = this
				let opts = {
					way: true, //true JSON请求；false 表单请求
					method: 'post',
					url: 'order-issue/apply/admin'
				};
				let data = {
					orderIssueId: _this.orderIssueId,
					reComments:_this.comments,
					reImages:_this.image_array,
				};
				_this.http.httpTokenRequest(opts, data).then(res => {
					if(res.code==200){
						_this.$refs.uToast.show({
							title: res.message,
							type: 'success'
						})
						setTimeout(function(){
							uni.navigateBack({
								delta:2,
							})
							// uni.switchTab({
							// 	url:'../../pages/home/home'
							// })
							// uni.navigateTo({
							// 	url:'./service'
							// })
						},500)
					}else{
						_this.$refs.uToast.show({
							title: res.message,
							type: 'error'
						})
					}
				})
			},
			del(index) {
				uni.showModal({
					title: '提示',
					content: '是否要删除该图片',
					success: res => {
						if (res.confirm) {
							this.imgList.splice(index, 1);
						}
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wait1{
		color: #666666;font-size: 30rpx;
	}
	.wait2{
		color: #3F3F3F;font-size: 26rpx;
	}
	.yes{
		padding: 26rpx 36rpx 26rpx 34rpx;color: #7A7A7A;font-size: 26rpx;
	}
	.line{
		height: 12rpx;width: 100%;background-color: #E8E8E8;
	}
	.want{
		border-bottom:2rpx solid #DCDCDC;padding: 20rpx 0 22rpx 36rpx;
	}
	.source{
		padding: 20rpx 0 0 34rpx;font-size: 26rpx;color: #979797;
	}
	
	.texs{
		padding: 6rpx;
	}
	#border{
		width: 650rpx;
		height: 280rpx;
		font-size: 26rpx;
		color: #979797;
		font-weight: 400;
	}
	.choose{
		width: 100%;
		display: flex;
		justify-content: flex-start;
		flex-wrap: wrap;
		.item{
			width: 184rpx;
			height: 184rpx;
			position: relative;
			margin-right: 25rpx;
			margin-top: 20rpx;
			image{
				width: 100%;
				height: 100%;
			}
			.no{
				width: 30rpx;
				height: 30rpx;
				position: absolute;
				top:-15rpx;
				right: -15rpx;
			}
		}
	}
	.xiuxiu{
		display: flex;
		align-items: center;
	}
	.footer {
		width: 100%;
		opacity: 1;
	}
	
	.foot_mon {
		text-align: center;
		padding: 38rpx 54rpx 32rpx 54rpx;
	}
</style>
